'''
绘图API: 绘制文本

1. 文本
2. 各种图形
3， 图像

painter = QPainter()
painter.begin()
painter.drawText(......)
painter.end()

必须在 paintEvent 事件方法中绘制各种元素。


绘制 像素点
drowPoint(x, y)

'''

import sys
import math
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

class DrawText(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("drawing text and points")
        self.resize(300, 200)
        self.text = 'python'
    def paintEvent(self, event):
        painter = QPainter()

        painter.begin(self)

        pen = QPen(Qt.red, 3, Qt.SolidLine)
        painter.setPen(pen)
        painter.drawLine(20, 40, 250, 40)

        # painter.setPen(QColor(150, 43, 5))
        # painter.setFont(QFont('Simsun', 25))
        # painter.drawText(event.rect(), Qt.AlignCenter, self.text)


        # painter.setPen(Qt.blue)
        # size = self.size()
        #
        # for i in range(1000):
        #     x = 100*(-1 + 2.0*i/100) + size.width()/2.0
        #     y = -50*math.sin((x - size.width()/2.0)*math.pi/50) + size.height()/2.0
        #     painter.drawPoint(x, y)
        painter.end()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = DrawText()
    ex.show()
    sys.exit(app.exec_())